1 module hip.api.audio; 2 public import hip.api.audio.audiosource; 3 public import hip.api.audio.audioclip; 4 5 //Low weight shared data 6 enum HipAudioType : ubyte 7 { 8 SFX, 9 MUSIC 10 } 11 12 /** 13 * Controls how the gain will falloff 14 */ 15 enum DistanceModel 16 { 17 DISTANCE_MODEL, 18 /** 19 * Very similar to the exponential curve 20 */ 21 INVERSE, 22 INVERSE_CLAMPED, 23 /** 24 * Linear curve, the only which can achieve 0 volume 25 */ 26 LINEAR, 27 LINEAR_CLAMPED, 28 29 /** 30 * Exponential curve for the model 31 */ 32 EXPONENT, 33 /** 34 * When the distance is below the reference, it will clamp the volume to 1 35 * When the distance is higher than max distance, it will not decrease volume any longer 36 */ 37 EXPONENT_CLAMPED 38 } 39 40 enum HipAudioImplementation : ubyte 41 { 42 Null, 43 OpenAL, 44 OpenSLES, 45 XAudio2, 46 WebAudio, 47 AVAudioEngine 48 } 49 50 HipAudioImplementation getAudioImplementationForOS() 51 { 52 with(HipAudioImplementation) 53 { 54 version(NullAudio) return Null; 55 else version(Android) return OpenSLES; 56 else version(Windows) return XAudio2; 57 else version(WebAssembly) return WebAudio; 58 else version(iOS) return AVAudioEngine; 59 else return OpenAL; 60 } 61 } 62 63 /** 64 * This is an interface that should be created only once inside the application. 65 * Every audio function is global, meaning that every AudioSource will refer to the player 66 */ 67 public interface IHipAudioPlayer 68 { 69 //LOAD RELATED 70 public bool play_streamed(AHipAudioSource src); 71 public IHipAudioClip getClip(); 72 public IHipAudioClip loadStreamed(string path, uint chunkSize); 73 public void updateStream(AHipAudioSource source); 74 public AHipAudioSource getSource(bool isStreamed = false, IHipAudioClip clip = null); 75 76 public void onDestroy(); 77 public void update(); 78 } 79 80 private __gshared IHipAudioPlayer audioPlayer; 81 void setIHipAudioPlayer(IHipAudioPlayer player) 82 { 83 audioPlayer = player; 84 } 85 86 IHipAudioPlayer HipAudio() 87 { 88 return audioPlayer; 89 }